package com.itheima.vms.controller;


import com.itheima.vms.domain.dto.SupplierDto;
import com.itheima.vms.domain.po.Supplier;
import com.itheima.vms.response.Result;
import com.itheima.vms.service.ISupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 渠道商表 前端控制器
 * </p>
 *
 * @author shenkunlin
 * @since 2025-08-02
 */
@RestController
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    private ISupplierService supplierService;
    //查询所有
    @GetMapping
    public Result<List<Supplier>> list(){
        return Result.ok(supplierService.list());
    }
    //分页查询
    @GetMapping("page")
    public Result querySupplier(SupplierDto dto){
        return Result.ok(supplierService.getPage(dto));
    }
    //新增
    @PostMapping
    public Result addSupplier(@RequestBody Supplier supplier){
        supplier.setCreateTime(LocalDateTime.now());
        supplier.setUpdateTime(LocalDateTime.now());
        supplierService.save(supplier);
        return Result.ok();
    }
    //回显查询
    @GetMapping("{id}")
    public Result getSupplierById(@PathVariable Integer id){
        Supplier supplier = supplierService.getById(id);
        return Result.ok(supplier);
    }
    //修改
    @PutMapping
    public Result updateSupplierById(@RequestBody Supplier supplier){
        return Result.ok(supplierService.updateById(supplier));
    }
    //删除
    @DeleteMapping("{id}")
    public Result deleteSupplierById(@PathVariable Integer id){
        return Result.ok(supplierService.removeById(id));
    }


}
